package com.longrise.android.byjk.plugins.tabthird.personal;

import com.longrise.LEAP.Base.Objects.EntityBean;
import com.longrise.android.byjk.common.UrlConstants;
import com.longrise.android.byjk.model.UserInfor;
import com.longrise.android.loaddata.newloaddata.LoadDataManagerFather;
import com.longrise.common.datasource.remote.LoadDataManager;
import com.longrise.common.utils.DZZWTools;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2018/3/6.
 * 更换背景presenter
 */

public class ChangeSeniorWallPresenter extends ChangeSeniorWallContract.Presenter{

    private List<BackGroundWallBean> mParentBeanList = new ArrayList<>();

    @Override
    protected void init() {
        getSeniorWallData();
    }


    public void getSeniorWallData(){

        EntityBean bean = new EntityBean();
        bean.set("userid ", UserInfor.getInstance().getUserid());
        bean.set("cardno ", UserInfor.getInstance().getUsersfzh());
        EntityBean fbean = new EntityBean();
        fbean.set("bean", bean);
        LoadDataManager.getInstance().callService2("", UrlConstants.BaseUrl,
                "bbt_vip_sCostBygoodstype", fbean, new LoadDataManager.OnRequestCallListener2() {

                    @Override
                    public void onSuccess(String key, String service, Object result) {
                        parseSortData(result);
                    }

                    @Override
                    public void onError(String key,String service, LoadDataManagerFather.ResultType resultType) {

                    }

                    @Override
                    public void onFinished(String key, String service) {
                        DZZWTools.dismissDialog(null);
                    }
                });
    }


    //解析更换背景高级分类
    public void parseSortData(Object result) {

        if (result != null) {
            EntityBean bean = (EntityBean) result;
            Integer resultstate = bean.getInt("resultstate");
            if (resultstate == 1) {
                EntityBean[] results = bean.getBeans("result");
                if (results != null) {
                    for (EntityBean resultbean : results) {
                        String id = resultbean.getString("id");
                        String areaname = resultbean.getString("areaname");
                        BackGroundWallBean wallBean = new BackGroundWallBean();
                        wallBean.setId(id);
                        wallBean.setAreaname(areaname);
                        mParentBeanList.add(wallBean);
                    }
                    mView.initAdapter(mParentBeanList);
                }
            }
        }else{

        }
    }
}
